package com.ruoyi.web.course;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.SExam;
import com.ruoyi.course.service.ISExamService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生考试Controller
 * 
 * @author ruoyi
 * @date 2024-11-30
 */
@RestController
@RequestMapping("/course/s_exam")
public class SExamController extends BaseController
{
    @Autowired
    private ISExamService sExamService;

    /**
     * 查询学生考试列表
     */
    @PreAuthorize("@ss.hasPermi('course:s_exam:list')")
    @GetMapping("/list")
    public TableDataInfo list(SExam sExam)
    {
        startPage();
        List<SExam> list = sExamService.selectSExamList(sExam);
        return getDataTable(list);
    }

    /**
     * 导出学生考试列表
     */
    @PreAuthorize("@ss.hasPermi('course:s_exam:export')")
    @Log(title = "学生考试", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SExam sExam)
    {
        List<SExam> list = sExamService.selectSExamList(sExam);
        ExcelUtil<SExam> util = new ExcelUtil<SExam>(SExam.class);
        util.exportExcel(response, list, "学生考试数据");
    }

    /**
     * 获取学生考试详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:s_exam:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sExamService.selectSExamById(id));
    }

    /**
     * 新增学生考试
     */
    @PreAuthorize("@ss.hasPermi('course:s_exam:add')")
    @Log(title = "学生考试", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SExam sExam)
    {
        return toAjax(sExamService.insertSExam(sExam));
    }

    /**
     * 修改学生考试
     */
    @PreAuthorize("@ss.hasPermi('course:s_exam:edit')")
    @Log(title = "学生考试", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SExam sExam)
    {
        return toAjax(sExamService.updateSExam(sExam));
    }

    /**
     * 删除学生考试
     */
    @PreAuthorize("@ss.hasPermi('course:s_exam:remove')")
    @Log(title = "学生考试", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sExamService.deleteSExamByIds(ids));
    }
}
